$(function () {
  let form = layui.form;
  //获取id
  let id = location.search;
  //console.log(id);
  id = id.substr(4, 2);
  //console.log(id);
  //获取列表信息
  $.ajax({
    url: "admin/users/" + id,
    success: function (res) {
      // console.log(res);
      // 把获取到的结果赋值给表单 form.val('filter', object);
      form.val("editForm", res.data);
    },
  });
  //编辑用户
  $("#edit-form").submit(function (e) {
    e.preventDefault();
    let data = $(this).serialize() +"&id="+id; //
    //console.log(data);
    $.ajax({
      url: "admin/users",
      type: "PUT",
      data,
      success: function (res) {
       // console.log(res);
        if (res.status !== 0) {
          return layer.msg(res.message);
        } else {
          layer.msg(res.message);
          //list()
        }
      },
    });
  });
});
